package com.woke.adapter;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import cn.xl.xxl.imagecache.ImageLoader;

import com.zhongcai.online.R;
import com.woke.data.Datas_perbor1;
import com.woke.method.Bitmapr;
import com.woke.method.Intentnet;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class Personboradter extends BaseAdapter{
	private LayoutInflater mInflater;
	private int screenWidth;
	private List<Datas_perbor1> datalist;
	private ImageLoader imageLoader;
	private Bitmapr bit;
	private String strtime;//��ǰʱ��
	private String timejls;
	private int timejlss;

	public Personboradter(LayoutInflater minflater, ArrayList<Datas_perbor1> datalist,ImageLoader imageLoader) {
		this.mInflater = minflater;
		this.datalist = datalist;
		this.imageLoader = imageLoader;
	}
	
	public void getcurrenttime() {
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy年MM月dd日");       
		Date curDate = new Date(System.currentTimeMillis());//��ȡ��ǰʱ��       
		strtime = formatter.format(curDate);
		timejls = Intentnet.getTime(strtime);
		timejlss = Integer.parseInt(timejls);
		Log.e("str", "str"+timejlss);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return datalist.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}
	
	class Holder {
		ImageView mImage_icon;
		TextView mText_time;
		TextView mText_lili;
		TextView mText_name;
		TextView mText_money,mText_address;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Holder holder = null;
		if(convertView == null){
			holder = new Holder();
			convertView = mInflater.inflate(R.layout.item_adapter_person, null);
			holder.mImage_icon = (ImageView) convertView.findViewById(R.id.item_personbo_icon);
			holder.mText_time = (TextView) convertView.findViewById(R.id.item_personbo_day);
			holder.mText_lili = (TextView) convertView.findViewById(R.id.item_personbo_lili);
			holder.mText_name = (TextView) convertView.findViewById(R.id.item_personbo_name);
			holder.mText_money = (TextView) convertView.findViewById(R.id.item_personbo_money);
			holder.mText_address = (TextView) convertView.findViewById(R.id.item_personbo_adress);
			convertView.setTag(holder);
		}else{
			 holder = (Holder) convertView.getTag();
		}
		Datas_perbor1 data = datalist.get(position);
//		holder.mText_time.setText(" "+data.exp_date+"��"+"  ");
		holder.mText_lili.setText(data.getInterest()+"%");
		holder.mText_name.setText(data.getUser_nicename());
		Double money = Double.valueOf(data.getQuota_money());
		if((money - 10000) >= 0){
			Double reust = money / 10000;
			holder.mText_money.setText(" "+reust+"万");
		}else{
			holder.mText_money.setText(" "+data.getQuota_money()+"元");
		}
		
		if(null == data.avatar || data.avatar.equals("")){
			
		}else{
			imageLoader.DisplayImage("http://"+data.getAvatar(), holder.mImage_icon, false, true, false,0);
		}
//		Bitmap bitmap = imageCache.getBitmapFromDiskCache("http://"+data.avatar);
//		if(bitmap != null){
//			bit = new Bitmapr();
//			if(null != bit){
//				holder.mImage_icon.setImageBitmap(bit.toRoundBitmap(bitmap,100));
//			}
//		}
		String creat_date = data.getCreat_date();
		String exp_date = data.getExp_date();
//		int adays = Integer.parseInt(exp_date);
//		int parseInt = Integer.parseInt(creat_date);
//		int newtiem = timejlss - parseInt;//ʣ������
//		if(newtiem / (3600*24) <= 1){
//			newtiem = 1;
//			Log.e("**^*"+newtiem, "**^*"+newtiem);
//		}else if((newtiem / (3600*24)) > 30){
//			newtiem = adays ;
//			Log.e("***"+newtiem, "***"+newtiem);
//		}else{
//			newtiem = newtiem / (3600*24);
//			Log.e("**"+newtiem, "**"+newtiem);
//		}
//		int lastsl = adays-newtiem;
//		if(lastsl < 0){
//			lastsl = 1;
//		}
		holder.mText_address.setText(data.getProvince_id()+data.getCity_id());
		holder.mText_time.setText(" "+exp_date+"天"+"  ");
//		Double reust = money / 10000;
//		holder.mText_money.setText(reust+"��");
		return convertView;
	}

}
